%filenames parser
%scanner ../scanner/scanner.h
%baseclass-preinclude "header.h"



%union{
	string* s_val;
}


%token<s_val> UNQUOT_S QUOT_S
%token<s_val> VERSION 
%token<s_val> PLACED UNPLACED BONDED UNBONDED
%token<s_val> INST INSTANCE 
%token BID_UNB BID_BUF BID_BUF_BOTH DIR_BUF
%token OUTPIN INPIN DRIVER LOAD COMMA 
%token<s_val> VCC VDD POWER GND GROUND WIRE NET
%token SEMICOLON CFG MODULE 
%token ENDMODULE PORT PIP DESIGN

%type<s_val> name part device package speed
%type<s_val> inst_prefix_id inst_name inst_type inst_placed inst_unplaced tile_name primitive_site
%type<s_val> string inst_pin_name net_name net_type



%start file

%%

file		: design statements {	
					ACCEPT();
				};
design		: DESIGN name part VERSION COMMA 
		| DESIGN name device package speed VERSION COMMA;
name		: QUOT_S ;
part		: UNQUOT_S ;
device		: UNQUOT_S ;
package		: UNQUOT_S ;
speed		: UNQUOT_S ;

statements	: statement 
		| statements statement ;
statement	: module SEMICOLON
		| inst SEMICOLON 
		| net SEMICOLON
		| inst_cfg SEMICOLON;

/* devo trovare degli esempi per provare i module */

module		: module_beg module_ports module_stmts module_end ;
module_beg	: MODULE module_name SEMICOLON
		| MODULE module_name anchor_name SEMICOLON ;
module_ports	: module_port
		| module_ports module_port ;
module_port	: PORT port_name net_name SEMICOLON
		| PORT port_name inst_name inst_pin_name SEMICOLON ;
module_stmts	: module_stmt
		| module_stmts module_stmt ;
module_stmt	: inst
		| net ;
module_end	: ENDMODULE module_name ;
module_name	: string ;
anchor_name	: string ;
port_name	: string ;

inst		: inst_prefix inst_stmts ;
inst_prefix	: inst_prefix_id inst_name inst_type { 
								g.addVertex($2, d_scanner.getLine());
							}; 
inst_prefix_id	: INST
		| INSTANCE ;
inst_name	: string ;
inst_type	: string ;

inst_stmts	: inst_stmt
		| inst_stmts inst_stmt ;
inst_stmt	: COMMA inst_placement
		| COMMA inst_module
		| COMMA inst_cfg ;
inst_placement	: inst_placed 
		| inst_unplaced ;
inst_placed	: PLACED tile_name primitive_site {
							g.setSite($3);
							};
inst_unplaced	: UNPLACED
		| UNPLACED BONDED
		| UNPLACED UNBONDED ;
inst_module	: MODULE module_name ;

inst_cfg	: CFG QUOT_S;

tile_name	: string ;
primitive_site	: string ;

inst_pin_name	: string ;

net		: NET net_name net_type COMMA net_stmts {
								g.setNet($2, $3);
							}
		| NET net_name net_type SEMICOLON {}
		| NET net_name  COMMA net_stmts {
							g.setNet($2);
						};
net_name	: string ;

net_type	: VCC 
		| VDD
		| POWER
		| GND
		| GROUND
		| WIRE ;

net_stmts	: net_stmt 
		| net_stmts net_stmt ;

net_stmt	: net_inpin COMMA
		| net_outpin COMMA 
		| net_pip COMMA
		| inst_cfg COMMA;
net_inpin	: INPIN inst_name inst_pin_name {	
							g.addInPin($2, $3, d_scanner.getLine());
	
						}
		|  LOAD inst_name inst_pin_name ;
net_outpin	: OUTPIN inst_name inst_pin_name {
							g.setOutPin($2, $3, d_scanner.getLine());
							
						}
		|  DRIVER inst_name inst_pin_name ;
net_pip		: PIP tile wire0 pip_direction wire1 ;
tile		: string ;
wire0		: string ;
pip_direction	: BID_UNB 
		| BID_BUF 
		| BID_BUF_BOTH 
		| DIR_BUF ;
wire1		: string ;
string		: UNQUOT_S | QUOT_S ;
